<template><el-row style="height: 100%">
	<el-col :span="8" :offset="8" style="border: 2px solid #e6e6e6; border-radius: 15px; margin-top: 10%">
		<el-row s>
			<el-col :span="16" :offset="4">
				<el-form>
					<h3>供应链金融应用</h3>
				</el-form>
				<el-form label-width="100px">
					<h3 style="margin: 15px 0">注册界面</h3>
					<el-form-item label="组织名称:">
						<el-input type="primary" v-model="registerForm.username"></el-input>
					</el-form-item>
					<el-form-item label="区块链地址:">
						<el-input type="primary" v-model="registerForm.address"></el-input>
					</el-form-item>
					<el-form-item label="组织类型:">
						<el-radio-group v-model="registerForm.orgType">
							<el-radio :label="1">公司</el-radio>
							<el-radio :label="2">银行</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-form>
			</el-col>
		</el-row>
		<el-row style="padding-bottom: 20px">
			<el-button type="primary" @click="register">注册</el-button>
			<el-button type="primary" @click="goback">返回</el-button>
		</el-row>
	</el-col>
</el-row></template>

<script>
export default {
	name: 'FrontMeRegister',

	data() {
		return {
			registerForm: {
				orgType: 1,
				username: '',
				address: '',
			},
		}
	},

	methods: {
		register() {
			if (this.registerForm.address === '') {
				this.$message.warning('用户地址不能为null')
				return
			} else if (!this.registerForm.address.startsWith('0x')) {
				this.$message.warning('用户地址不合法')
				return
			}

			if (this.registerForm.username === '') {
				this.$message.warning('用户名不能为null')
				return
			}

			if (this.registerForm.orgType === '') {
				this.$message.warning('用户名类型为null')
				return
			}

			this.$axios.post('/finance/org/register', this.registerForm).then((res) => {
				if (res.code == 200) {
					this.$router.push('/login')
				}
			})
		},
		goback() {
			for (const key in this.registerForm) {
				this.registerForm[key] = ''
			}
			this.$router.push('/login')
		},
	},
}
</script>

<style lang="sass" scoped></style>
